

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'work/index' + location.search,
                    add_url: 'work/add',
                   // edit_url: 'work/edit',
                    del_url: 'work/del',
                    multi_url: 'work/multi',
                    import_url: 'work/import',
                    dr_url: 'work/dr',
                    table: 'work',
                    export_url: 'work/export',//导出路径
                    export_service_url: 'work/serviceexport',//导出路径
                    export_log_url: 'work/logexport',//导出路径
                }
            });

            var table = $("#table");
            //改为在保
            $(document).on("click", ".btn-type1", function () {
                var data = table.bootstrapTable('getSelections');
                console.log(data);
                var ids = [];
                if (data.length === 0) {
                    Toastr.error("请选择操作信息");
                    return;
                }
                for (var i = 0; i < data.length; i++) {
                    ids[i] = data[i]['id']
                }

                Layer.confirm(

                    '确认选中的' + ids.length + '条改为在保吗?', {
                        icon: 3,
                        title: __('Warning'),
                        offset: '40%',
                        shadeClose: true
                    },
                    function (index) {
                        Layer.close(index);
                        Backend.api.ajax({
                            //url: "lgwy/attrchg/approve?ids=" + JSON.stringify(ids),
                            //方法一：传参方式，后台需要转换变成数组
                            /*url: "lgwy/attrchg/approve?ids=" + (ids),
                            data: {}*/
                            //方法二：传参方式，直接是数组传递给后台
                            url: "work/userbao",
                            data: {
                                ids: ids
                            }
                        }, function (data, ret) { //成功的回调
                            if (ret.code === 1) {

                                table.bootstrapTable('refresh');
                                Layer.close(index);
                            } else {
                                Layer.close(index);
                                Toastr.error(ret.msg);
                            }
                        }, function (data, ret) { //失败的回调
                            console.log(ret);
                            // Toastr.error(ret.msg);
                            Layer.close(index);
                        });
                    }
                );
                $("#zhuanji").hide();
            });
//导出
            $(document).on("click", ".btn-export-two", function () {
                var ids = Table.api.selectedids(table);
                var page = table.bootstrapTable('getData');
                var all = table.bootstrapTable('getOptions').totalRows;
                console.log(ids, page, all);

                Layer.confirm("<form action='" + Fast.api.fixurl($.fn.bootstrapTable.defaults.extend.export_service_url) + "' method='post' target='_blank'>" +
                    "<input type='hidden' name='ids' value='' />" +
                    "<input type='hidden' name='filter' >" +
                    "<input type='hidden' name='op'>" +
                    "<input type='hidden' name='search'>" +
                    "<input type='hidden' name='columns'></form>", {

                    //title: '导出成功',
                   btn: ["导出成功"],

                    success: function (layero, index) {

                        console.log(layero);
                        var options = table.bootstrapTable('getOptions');
                        console.log(options);
                        var columns = [];
                        $.each(options.columns[0], function (i, j) {
                            if (j.field && !j.checkbox && j.visible && j.field != 'operate') {
                                columns.push(j.field);
                            }
                        });
                        var search = options.queryParams({});
                        $("input[name=search]", layero).val(options.searchText);
                        $("input[name=ids]", layero).val(ids);
                        $("input[name=filter]", layero).val(search.filter);
                        $("input[name=op]", layero).val(search.op);
                        $("input[name=columns]", layero).val(columns.join(','));
                        $("form", layero).submit();
                        layer.closeAll('dialog');
                        return false;
                    },

                });
            });
            //导出
            $(document).on("click", ".btn-export-log", function () {
                //var ids = Table.api.selectedids(table);
                var page = table.bootstrapTable('getData');
                var all = table.bootstrapTable('getOptions').totalRows;

                let order = $(this).data('order');
                let ids =order.id;
                console.log(order.id + "ddddddd"+ids);

                Layer.confirm("<form action='" + Fast.api.fixurl($.fn.bootstrapTable.defaults.extend.export_log_url) + "' method='post' target='_blank'>" +
                    "<input type='hidden' name='ids' value='' />" +
                    "<input type='hidden' name='filter' >" +
                    "<input type='hidden' name='op'>" +
                    "<input type='hidden' name='search'>" +
                    "<input type='hidden' name='columns'></form>", {

                    //title: '导出数据',
                    //btn: ["选中项11(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],

                    success: function (layero, index) {

                        console.log(layero);
                        var options = table.bootstrapTable('getOptions');
                        console.log(options);
                        var columns = [];
                        $.each(options.columns[0], function (i, j) {
                            if (j.field && !j.checkbox && j.visible && j.field != 'operate') {
                                columns.push(j.field);
                            }
                        });
                        var search = options.queryParams({});
                        $("input[name=search]", layero).val(options.searchText);
                        $("input[name=ids]", layero).val(ids);
                        $("input[name=filter]", layero).val(search.filter);
                        $("input[name=op]", layero).val(search.op);
                        $("input[name=columns]", layero).val(columns.join(','));
                        $("form", layero).submit();
                        layer.closeAll('dialog');
                        return false;
                    },

                });
            });
            //////////////
            $(document).on("click", ".btn-export", function () {
                var ids = Table.api.selectedids(table);
                var page = table.bootstrapTable('getData');
                var all = table.bootstrapTable('getOptions').totalRows;
                console.log(ids, page, all);
                Layer.confirm("请选择导出的选项<form action='" + Fast.api.fixurl($.fn.bootstrapTable.defaults.extend.export_url) + "' method='post' target='_blank'>" +
                    "<input type='hidden' name='ids' value='' />" +
                    "<input type='hidden' name='filter' >" +
                    "<input type='hidden' name='op'>" +
                    "<input type='hidden' name='search'>" +
                    "<input type='hidden' name='columns'></form>", {

                    title: '导出数据',
                    btn: ["选中项(" + ids.length + "条)", "本页(" + page.length + "条)", "全部(" + all + "条)"],
                    success: function (layero, index) {
                        $(".layui-layer-btn a", layero).addClass("layui-layer-btn0");
                    },
                    yes: function (index, layero) {
                        submitForm(ids.join(","), layero);
                        return false;
                    },
                    btn2: function (index, layero) {
                        var ids = [];
                        $.each(page, function (i, j) {
                            ids.push(j.id);
                        });
                        submitForm(ids.join(","), layero);
                        return false;
                    },
                    btn3: function (index, layero) {
                        submitForm("all", layero);
                        return false;
                    }
                })
            });

            var submitForm = function (ids, layero) {
                var options = table.bootstrapTable('getOptions');
                console.log(options);
                var columns = [];
                $.each(options.columns[0], function (i, j) {
                    if (j.field && !j.checkbox && j.visible && j.field != 'operate') {
                        columns.push(j.field);
                    }
                });
                var search = options.queryParams({});
                $("input[name=search]", layero).val(options.searchText);
                $("input[name=ids]", layero).val(ids);
                $("input[name=filter]", layero).val(search.filter);
                $("input[name=op]", layero).val(search.op);
                $("input[name=columns]", layero).val(columns.join(','));
                $("form", layero).submit();
            };
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                       /* {field: 'xh', title: __('序号'),operate:false},
                        {field: 'sdrq', title: __('收到日期'),operate:false},
                        {field: 'sales_status', title: __('售后确认修改状态'),operate:false},
                        {field: 'factory_status', title: __('工厂检查维修状态'),operate:false},*/
                        {field: 'channel.name', title: __('购买渠道'),operate:false},
                        {field: 'channel.id', title: __('购买渠道'), visible: false, searchList: $.getJSON("channel/getList")},
                        {field: 'status', title: __('Status'),operate:false, searchList: {"1":__('待审核'),"2":__('已驳回'),"3":__('待用户寄出'),"4":__('待工厂收货'),"5":__('工厂检测中'),"6":__('待确认检查结果'),"7":__('待上传凭证'),"8":__('凭证待审核'),"9":__('待工厂寄出'),"10":__('已完成'),"11":__('已撤回')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), visible: false, searchList: $.getJSON("channel/getStatus"), formatter: Table.api.formatter.status},
                        {field: 'factory.title', title: __('售后工厂'),operate:false},
                        {field: 'factory.id', title: __('售后工厂'), visible: false, searchList: $.getJSON("factory/getList")},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'real_pay_time', title: __('用户购买时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order_image', title: __('用户购买时间截图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'voucher', title: __('支付截图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},




                        {field: 'id', title: __('系统工单'),
                            formatter: function(value, row){

                                var type_name = row.is_two == 1 ? value+" <i class='fa fa-chrome'></i>" : value;
                                return type_name;
                            }},
                        {field: 'confirm_time', title: __('工厂确认收件时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'sales_status', title: __('客户确认维修状态'),operate:'LIKE'},
                        {field: 'is_liugc', title: __('工厂维修状态'), searchList: {"0":__('无'),"1":__('不寄'),"2":__('已寄出')}, formatter: Table.api.formatter.status},

                        {field: 'product.name', title: __('产品名称'),operate:'LIKE'},
                        {field: 'product.code', title: __('产品序列号'),operate:'LIKE'},
                        {field: 'pro_bao', title: __('工厂质保状态'), searchList: {"0":__('过保'),"1":__('在保')}, formatter: Table.api.formatter.status},
                        {field: 'work_bao', title: __('用户质保状态'), searchList: {"0":__('过保'),"1":__('在保')}, formatter: Table.api.formatter.status},
                        {field: 'res_receiver', title: __('用户名'),operate:'LIKE'},
                        {field: 'res_mobile', title: __('用户电话'),operate:'LIKE'},
                        //{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'res_address', title: __('用户地址'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,
                            formatter: function(value, row){

                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},

                        {field: 'user_content', title: __('用户描述故障'),operate:false},
                        {field: 'user_shipper_code', title: __('用户寄出单号'),operate:'LIKE'},
                        {field: 'jxsfdff', title: __('用户寄修顺丰到付费'),operate:'LIKE'},
                        {field: 'fantime', title: __('再次寄修记录'),visible:false, searchList: {"0.5":__('半月内'),"1":__('一个月内'),"2":__('两个月内'),"3":__('三个月内'),"6":__('半年内')},},
                        {field: 'fan_time', title: __('再次寄修记录'),operate:false},
                        {field: 'remarks', title: __('备注'),operate:false},
                        {field: 'damage_reason', title: __('检测类型'), searchList: {"0":__('无'),"1":__('非质量问题'),"2":__('质量问题')}, formatter: Table.api.formatter.status},
                        {field: 'detection_content', title: __('检测结果'),operate:'LIKE'},
                        {field: 'cost', title: __('总费用'),operate:'LIKE'},
                        {field: 'cost_content', title: __('费用说明'),operate:false},
                        {field: 'admin_shipper_code', title: __('工厂寄回单号'),operate:'LIKE'},
                        {field: 'factorysend_time', title: __('工厂寄出日期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetimeday},





                        {field: 'gc_cl_time', title: __('工厂处理时间'), operate: false},

/*



                        /!* {field: 'admin.username', title: __('Admin_id'),operate:'LIKE'},*!/
                        {field: 'user_shipper_code', title: __('用户寄出单号'),operate:'LIKE'},




                        {field: 'user_content', title: __('备注'),operate:'LIKE'},
*/
                        {field: 'is_huangou', title: __('是否换购'), searchList: {"0":__('无-修好寄回'),"1":__('是，旧笔留工厂'),"2":__('否，旧笔寄回'),"3":__('否，旧笔留工厂'),"4":__('否，需维修')}, formatter: Table.api.formatter.status},
                        {field: 'complete_remarks', title: __('备注2'),operate:'LIKE'},
                        {field: 'confirmdetection_time', title: __('确认检测结果时间'),visible:false, operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
/*

                        {field: 'is_liugc', title: __('是否留在工厂'), searchList: {"1":__('是'),"2":__('否')}, formatter: Table.api.formatter.status,visible:false},

                        {field: 'problem', title: __('故障问题'),operate:false},
*/







                        /*{field: 'gc_cl_time', title: __('工厂处理时间'), operate: false},
                        {field: 'fantime', title: __('二次返修时间'),visible:false, searchList: {"0.5":__('半月内'),"1":__('一个月内'),"2":__('两个月内'),"3":__('三个月内'),"6":__('半年内')},},
                        {field: 'fan_time', title: __('二次返修时间'),operate:false},
                        {field: 'product.name', title: __('产品名称'),operate:'LIKE'},
                        {field: 'product.code', title: __('产品序列号'),operate:'LIKE'},
                        {field: 'pro_bao', title: __('工厂质保状态'),operate:'LIKE'},
                        {field: 'work_bao', title: __('用户质保状态'),operate:'LIKE'},
                        {field: 'res_receiver', title: __('用户名'),operate:'LIKE'},
                        {field: 'res_mobile', title: __('用户电话'),operate:'LIKE'},
                        //{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'res_address', title: __('用户地址'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,
                            formatter: function(value, row){

                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},
                        {field: 'channel.name', title: __('购买渠道'),operate:false},
                        {field: 'channel.id', title: __('购买渠道'), visible: false, searchList: $.getJSON("channel/getList")},
                        {field: 'status', title: __('Status'), searchList: {"1":__('待审核'),"2":__('已驳回'),"3":__('待用户寄出'),"4":__('待工厂收货'),"5":__('工厂检测中'),"6":__('待确认检查结果'),"7":__('待上传凭证'),"8":__('凭证待审核'),"9":__('待工厂寄出'),"10":__('已完成'),"11":__('已撤回')}, formatter: Table.api.formatter.status},
                       /!* {field: 'admin.username', title: __('Admin_id'),operate:'LIKE'},*!/
                        {field: 'factory.title', title: __('售后工厂'),operate:'LIKE'},
                        //{field: 'user_content', title: __('故障问题'),operate:'LIKE'},
                        {field: 'is_two', title: __('是否二次工单'),visible:false, searchList: {"0":__('否'),"1":__('是')},},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'confirm_time', title: __('确认收件时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'user_shipper_code',
                            title: '用户寄出单号',
                            operate: 'RANGE',
                            addclass: 'user_shipper_code',
                            autocomplete: false,
                            operate:false,
                            formatter: function (value, row, index) {
                                var type_name = row.user_shipper_name == null ? '' : row.user_shipper_name;
                                var type_name1 = row.user_shipper_code == null ? '' : row.user_shipper_code;
                                return type_name + ' - ' + type_name1;
                            }
                        },
                        {
                            field: 'admin_shipper_code',
                            title: '工厂寄回单号',
                            operate: 'RANGE',
                            addclass: 'admin_shipper_code',
                            operate:false,
                            autocomplete: false,
                            formatter: function (value, row, index) {
                                var type_name = row.admin_shipper_name == null ? '' : row.admin_shipper_name;
                                var type_name1 = row.admin_shipper_code == null ? '' : row.admin_shipper_code;
                                return type_name + ' - ' + type_name1;
                            }
                        },
                        {field: 'user_shipper_code', title: __('用户寄出单号'), visible: false,operate:'LIKE'},
                        {field: 'admin_shipper_code', title: __('工厂寄回单号'), visible: false,operate:'LIKE'},
                        {field: 'user_content', title: __('用户说明'),operate: false},
                        {field: 'remarks', title: __('remarks'),operate: 'LIKE'},

                        {field: 'shop_name', title: __('店铺名称'),operate: 'LIKE',visible:false},
                        {field: 'order_code', title: __('订单编号'),operate: 'LIKE',visible:false},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit  - 删除按钮operate-del
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },
                            buttons: [
                                /*{
                                    name: 'ajax',
                                    text:'设置为已完成',//按钮名称
                                    title:'设置为已完成',//按钮名称
                                    classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    icon: 'fa fa-magic',
                                    confirm: '确认设置为已完成？',
                                    //url: 'device/readIC?id='+row.id,
                                    url: function (row) {
                                        return 'work/chagewc?id='+row.id
                                    },
                                    success: function (data, ret) {
                                        // Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                    error: function (data, ret) {
                                        console.log(data, ret);
                                        Layer.alert(ret.msg);
                                        return false;
                                    }
                                },*/
                                {
                                    name: 'click',
                                    title: __('审核'),
                                    text: __('审核'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shenhe',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('审核'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shenhelook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('撤回'),
                                    text: __('撤回'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shenhechehui',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/xiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 11){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('已驳回'),
                                    text: __('驳回查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/bohuide',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 2){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('手动上传快递'),
                                    text: __('手动上传快递'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/usersend',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 3){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待用户寄出'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/usersendlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 3){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('确认收货'),
                                    text: __('确认收货'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/confirm',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 4){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待工厂收货'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/confirmlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 4){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('上传检测报告'),
                                    text: __('上传检测报告'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/detection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('工厂确认中'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/sclookdetection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待售后客服确认'),
                                    text: __('确认检测结果'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/confirmdetection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 6){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待售后客服确认'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/lookdetection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 6){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('手动上传凭证'),
                                    text: __('手动上传凭证'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/voucher',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 7){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待上传凭证'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/voucherlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 7){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('审核凭证'),
                                    text: __('审核凭证'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shvoucher',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 8){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('审核凭证'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shvoucherlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 8){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待工厂寄出'),
                                    text: __('待工厂寄出'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/factorysend',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 9){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待工厂寄出'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/factorysendlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 9){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('已完成'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/complete',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 10){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                }/*,
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/xiugaiputong',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status != 11 && (row.admin_type == 2 || row.admin_type == 3)){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                }*/,
                                {
                                    name: 'click',
                                    title: __('工作流'),
                                    text: __('工作流'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/worklog',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        return true;
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('维修记录'),
                                    text: __('维修记录'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/service',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        return true;
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){

                                        if(row.status == 3 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        if(row.status == 4 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        if(row.status == 5 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        if(row.status == 6 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        if(row.status == 7 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        if(row.status == 8 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('修改'),
                                    text: __('修改'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/tongxiugai',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 9 && row.admin_type != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            $(document).on('click', '.btn-dr-click', function () {
                /*let voucher = $("#c-voucher").val();
                let id = $('#c-id').val();*/
                let order = $(this).data('order');
                $.post('work/complete', {
                    //id,
                    ...order
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
        },
        delindex: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'work/delindex' + location.search,
                    //add_url: 'work/add',
                    // edit_url: 'work/edit',
                    //del_url: 'work/del',
                   // multi_url: 'work/multi',
                    //import_url: 'work/import',
                   // dr_url: 'work/dr',
                   // table: 'work',
                   // export_url: 'work/export',//导出路径
                   // export_service_url: 'work/serviceexport',//导出路径
                   // export_log_url: 'work/logexport',//导出路径
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,

                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),
                            formatter: function(value, row){

                                var type_name = row.is_two == 1 ? value+" <i class='fa fa-chrome'></i>" : value;
                                return type_name;
                            }},
                        {field: 'gc_cl_time', title: __('工厂处理时间'), operate: false},
                        {field: 'fantime', title: __('返修时间'),visible:false, searchList: {"0.5":__('半月内'),"1":__('一个月内'),"2":__('两个月内'),"3":__('三个月内'),"6":__('半年内')},},
                        {field: 'fan_time', title: __('返修时间'),operate:false},
                        {field: 'product.name', title: __('产品名称'),operate:'LIKE'},
                        {field: 'product.code', title: __('产品序列号'),operate:'LIKE'},
                        {field: 'pro_bao', title: __('工厂质保状态'),operate:'LIKE'},
                        {field: 'work_bao', title: __('用户质保状态'),operate:'LIKE'},
                        {field: 'res_receiver', title: __('用户名'),operate:'LIKE'},
                        {field: 'res_mobile', title: __('用户电话'),operate:'LIKE'},
                        //{field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'res_address', title: __('用户地址'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content,
                            formatter: function(value, row){

                                var type_name = value == null ? '' : value;
                                return type_name;
                            }},
                        {field: 'channel.name', title: __('购买渠道'),operate:false},
                        {field: 'channel.id', title: __('购买渠道'), visible: false, searchList: $.getJSON("channel/getList")},
                        {field: 'status', title: __('Status'), searchList: {"1":__('待审核'),"2":__('已驳回'),"3":__('待用户寄出'),"4":__('待工厂收货'),"5":__('工厂检测中'),"6":__('待确认检查结果'),"7":__('待上传凭证'),"8":__('凭证待审核'),"9":__('待工厂寄出'),"10":__('已完成'),"11":__('已撤回')}, formatter: Table.api.formatter.status,operate:false},
                        /* {field: 'admin.username', title: __('Admin_id'),operate:'LIKE'},*/
                        {field: 'factory.title', title: __('售后工厂'),operate:'LIKE'},
                        //{field: 'user_content', title: __('故障问题'),operate:'LIKE'},
                        {field: 'is_two', title: __('是否二次工单'),visible:false, searchList: {"0":__('否'),"1":__('是')},},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'confirm_time', title: __('确认收件时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'user_shipper_code',
                            title: '用户寄出单号',
                            operate: 'RANGE',
                            addclass: 'user_shipper_code',
                            autocomplete: false,
                            operate:false,
                            formatter: function (value, row, index) {
                                var type_name = row.user_shipper_name == null ? '' : row.user_shipper_name;
                                var type_name1 = row.user_shipper_code == null ? '' : row.user_shipper_code;
                                return type_name + ' - ' + type_name1;
                            }
                        },
                        {
                            field: 'admin_shipper_code',
                            title: '工厂寄回单号',
                            operate: 'RANGE',
                            addclass: 'admin_shipper_code',
                            operate:false,
                            autocomplete: false,
                            formatter: function (value, row, index) {
                                var type_name = row.admin_shipper_name == null ? '' : row.admin_shipper_name;
                                var type_name1 = row.admin_shipper_code == null ? '' : row.admin_shipper_code;
                                return type_name + ' - ' + type_name1;
                            }
                        },
                        {field: 'user_shipper_code', title: __('用户寄出单号'), visible: false,operate:'LIKE'},
                        {field: 'admin_shipper_code', title: __('工厂寄回单号'), visible: false,operate:'LIKE'},
                        {field: 'remarks', title: __('remarks')},
                        {field: 'shop_name', title: __('店铺名称'),operate: 'LIKE',visible:false},
                        {field: 'order_code', title: __('订单编号'),operate: 'LIKE',visible:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate
                            ,
                            buttons: [
                                {
                                    name: 'click',
                                    title: __('审核'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shenhelook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('已驳回'),
                                    text: __('驳回查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/bohuide',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 2){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待用户寄出'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/usersendlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 3){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待工厂收货'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/confirmlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 4){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('工厂确认中'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/sclookdetection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 5){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待售后客服确认'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/lookdetection',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 6){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待上传凭证'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/voucherlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 7){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('审核凭证'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/shvoucherlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 8){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('待工厂寄出'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/factorysendlook',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 9){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                },
                                {
                                    name: 'click',
                                    title: __('已完成'),
                                    text: __('查看'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-leaf',
                                    url: 'work/complete',
                                    //visible属性可以让按钮显示或者隐藏，这里通过判断status = 6就显示，否则就隐藏
                                    visible:function(row){
                                        console.log(row);
                                        if(row.status == 10){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                }
                                ]}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {

            $(document).on('change','#c-product_id',function () {
                    var val = $("#c-product_id").val();
                    $.ajax({
                        async: true,
                        url: 'work/getproduct',
                        type: 'GET',
                        data : { id : val },
                        dataType: 'json',
                        timeout: 30000,
                        success: function (rec) {
                            // $("#c-flow_id").val(rec.rows.mobile)
                            $("#c-product_name").val(rec.rows.product_name);
                            $("#c-factory_title").val(rec.rows.factory_title);
                            $("#c-factory_name").val(rec.rows.factory_name);
                            $("#c-factory_phone").val(rec.rows.factory_phone);
                            $("#c-factory_address").val(rec.rows.factory_address);
                            if(rec.rows.product_name == "数据线"){
                                $("#sone").hide();//表示display:block,
                                $("#sjx").hide();//表示display:block,
                                $("#sjx1").hide();//表示display:block,
                                $("#stwo").show();//表示display:none;
                            }else{
                                $("#sone").show();//表示display:block,
                                $("#stwo").hide();//表示display:none;
                            }
                        },
                    });
            });
            $("#sone").show();//表示display:block,
            $("#stwo").hide();//表示display:none;
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on('change','#c-product_id',function () {
                var val = $("#c-product_id").val();
                $.ajax({
                    async: true,
                    url: 'work/getproduct',
                    type: 'GET',
                    data : { id : val },
                    dataType: 'json',
                    timeout: 30000,
                    success: function (rec) {
                        // $("#c-flow_id").val(rec.rows.mobile)
                        $("#c-product_name").val(rec.rows.product_name);
                        $("#c-factory_title").val(rec.rows.factory_title);
                        $("#c-factory_name").val(rec.rows.factory_name);
                        $("#c-factory_phone").val(rec.rows.factory_phone);
                        $("#c-factory_address").val(rec.rows.factory_address);
                    },
                });
            });
            Controller.api.bindevent();
        },
        detection: function () {
            csmr();
            function csmr () {
                var popVal = 2;
                //let id = $("#damage_reason").val();
                // popVal = $(this).val();
                // alert(popVal);
                console.log("进入方法","number ="+popVal);
                if (popVal === '1') {
                    // 弹窗公告
                    //$("#cost").addClass('hide');
                    $("#cost_content").addClass('hide');
                    $("#problem_fzl").addClass('hide');
                    $("#problem_zl").removeClass('hide');
                    $("#repair_zl").removeClass('hide');
                } else {
                    // 活动公告
                    // $("#cost").removeClass('hide');
                    $("#problem_zl").hide(); // 隐藏
                    $("#repair_zl").hide(); // 隐藏

                }

            }
            $(document).on('click', '.btn-selectMultipleBtn-click', function () {
                let id = $("#c-id").val();
                parent.Fast.api.open('cost/index?ids='+id, __('上传检测报告'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            //用于追加行的实现,追加行之后，行值发生改变
            //fa.event.appendfieldlist事件是指，当用户在确认框的输入框中添加新字段时触发的事件
            //当在文档上发生fa.event.appendfieldlist事件时，为id为linetable的元素中class为btn-append的元素绑定一个函数，该函数接受e和obj两个参数。
            $(document).on("fa.event.appendfieldlist", "#linetable .btn-append", function (e, obj) {
                //绑定动态下拉组件,触发下拉列表功能，解决不会被渲染的问题
                Form.events.selectpage(obj);
                //绑定日期组件，触发日期选择功能
                Form.events.datetimepicker(obj);
                //判断id下linetable的长度
                var len = $('#linetable tr').length;
                console.info(len);
                //var cost_money_sun = 0;
                for (var i = 1; i < len - 1; i++) {
                   // var cost_money = $("#cost_money"+i).val();
                   // cost_money_sun = cost_money_sun + cost_money;
                    /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                    //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                    //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                }
                console.info(len);
               // $('#all_quantity').val(cost_money_sun);
                //选择页面弹窗
                //选择所有具有"form"角色的表单。
                var form = $("form[role=form]");
                //fachoosetable(form)是一个函数，它可以用来检查一个表单中的输入字段，以确保它们符合预定义的模式或规则。
                fachoosetable(form);
                //定义函数fachoosetable()
                function fachoosetable (form) {
                    console.log(2323);
                    // 如果表单中的".fachoosetable"元素的大小大于0，则执行下面的代码。
                    if ($(".fachoosetable", form).size() > 0) {
                        //对class为fachoosetable的组件执行点击事件
                        $(".fachoosetable", form).on('click', function () {
                            var that = this;
                            //获取该界面的前端页面传来的line（前端展示的是data-line）
                            var line = $(this).data("line") ? $(this).data("line") : false;
                            //获取该界面的前端界面传来的url
                            var product_id = $("#c-product_id").val();
                            var factory_id = $("#c-factory_id").val();
                            var url = $(this).data("url") ? $(this).data("url") : (typeof Backend !==
                            'undefined' ? "cost/select": "");
                            //打开弹窗
                           // console.log(product_id)
                            //parent.Fast.api.open(url + "?line=" + line + "&product_id="+product_id, __('Choose'), {
                            tables_list=[];
                            parent.Fast.api.open(url + product_id +"&factory_id"+factory_id, __('Choose'), {
                                //回传值
                                callback: function (data) {
                                    console.log("返回数据"+data);
                                    console.log(line);
                                    $.ajax({
                                        url: 'cost/selectQr?ids='+data,
                                        type: 'GET',
                                        dataType: 'json',
                                        data: {},
                                        success: function (res) {
                                            res.forEach(r=>{
                                                tables_list.push(
                                                    {
                                                        factory_name:r.factory_name,
                                                        product_name:r.product_name,
                                                        costmode_name:r.costmode_name,
                                                        cost_money:r.cost_money,
                                                        real_money:r.real_money,
                                                        qi:r.qi,
                                                        id:r.id,
                                                    }
                                                );
                                            });
                                            getListtbody();
                                        }
                                    });
                                    function getListtbody(){
                                        var html='';
                                        console.log(6666,tables_list);
                                        tables_list.forEach((r,index)=>{
                                            html+='<tr >';
                                            html+='<td> <input type="text" id="factory_title<%='+r.id+'+1%>" className="form-control" data-line="<%='+r.id+1+'%>" name="row[linedetail]'+r.id+'[factory_title]" value="'+r.factory_title+'" /></td>';
                                            html+='<td> <input type="text" id="product_name<%='+r.id+'+1%>" className="form-control" data-line="<%='+r.id+1+'%>" name="row[linedetail]'+r.id+'[product_name]" value="'+r.product_name+'"/></td>';
                                            html+='<td> <input type="text" id="costmode_name<%='+r.id+'+1%>" className="form-control" data-line="<%='+r.id+1+'%>" name="row[linedetail]'+r.id+'[costmode_name]" value="'+r.costmode_name+'"/></td>';
                                            html+='<td> <input type="text" onblur = "cost_money()" id="cost_money<%='+r.id+'+1%>" className="form-control" data-line="<%='+r.id+1+'%>" name="row[linedetail]'+r.id+'[cost_money]" value="'+r.cost_money+'" style="width: 50px;" /></td>';
                                            html+='<td> <input type="text" onblur = "cost_money()" id="real_money<%='+r.id+'+1%>" className="form-control" data-line="<%='+r.id+1+'%>" name="row[linedetail]'+r.id+'[real_money]" value="'+r.real_money+'" style="width: 50px;" /></td>';

                                            html+='<td><input type="checkbox" id="checkbox1" name="checkbox1"><label for="checkbox1">选项1</label> <span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';

                                            html+='</tr>';
                                        });
                                        console.log("xin");
                                        $('.lyj_tbody').html(html);
                                        var len = $('#linetable tr').length;
                                        console.log("xin"+len);
                                        var cost_money_sun = 0;
                                        var real_money_sun = 0;
                                        for (var i = 1; i < len - 1; i++) {
                                            var cost_money = $("#cost_money"+i).val();
                                            var real_money = $("#real_money"+i).val();
                                            cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                            real_money_sun = Number(real_money_sun) + Number(real_money);
                                            /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                                            //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                                            //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                                        }

                                        $('#all_quantity').val(cost_money_sun);
                                        $('#all_quantity_real').val(real_money_sun);
                                    }
                                   /* //直接给页面的该行数据定义值
                                    $("#factory_title"+line).val(data.row.factory_title);
                                    $("#product_name"+line).val(data.row.product_name);
                                    $("#costmode_name"+line).val(data.row.cost_name);
                                    $("#cost_money"+line).val(data.row.cost_money);*/

                                    var len = $('#linetable tr').length;
                                    console.info("xin"+len);
                                    var cost_money_sun = 0;
                                    var real_money_sun = 0;
                                    for (var i = 1; i < len - 1; i++) {
                                        var cost_money = $("#cost_money"+i).val();
                                        var real_money = $("#real_money"+i).val();
                                        cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                        real_money_sun = Number(real_money_sun) + Number(real_money);
                                        /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                                        //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                                        //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                                    }

                                    $('#all_quantity').val(cost_money_sun);
                                    $('#all_quantity_real').val(real_money_sun);
                                }
                            });
                            return false;
                        });
                    }
                }

            });
            $(document).on("click", ".fachoosetable", function () {
                var that = this;
                //获取该界面的前端页面传来的line（前端展示的是data-line）
                var line = $(this).data("line") ? $(this).data("line") : false;
                //获取该界面的前端界面传来的url
                var product_id = $("#c-product_id").val();
                var factory_id = $("#c-factory_id").val();
                var work_bao = $("#c-work_bao").val();
                var popVal = $("input[type=radio][name='row[damage_reason]']:checked").val();
                console.log("factory_id"+factory_id);
                var url = $(this).data("url") ? $(this).data("url") : (typeof Backend !==
                'undefined' ? "cost/select?product_id=": "");
                //打开弹窗
                // console.log(product_id)
                //parent.Fast.api.open(url + "?line=" + line + "&product_id="+product_id, __('Choose'), {
                tables_list=[];
                parent.Fast.api.open(url + product_id+"&factory_id="+factory_id, __('Choose'), {
                    //回传值
                    callback: function (data) {
                        console.log("返回数据"+data);
                        console.log(line);
                        $.ajax({
                            url: 'cost/selectQr?ids='+data,
                            type: 'GET',
                            dataType: 'json',
                            data: {},
                            success: function (res) {
                                res.forEach(r=>{
                                    tables_list.push(
                                        {
                                            factory_title:r.factory_title,
                                            product_name:r.product_name,
                                            costmode_name:r.cost_name,
                                            cost_money:r.cost_money,
                                            real_money:r.real_money,
                                            qi:r.qi,
                                            id:r.id,
                                            type:r.type,
                                        }
                                    );
                                });
                                getListtbody();
                            }
                        });
                        let su = $('.lyj_tbody tr').length;
                        su = su+20;
                        function getListtbody(){
                            var html='';
                            console.log(6666,tables_list);
                            tables_list.forEach((r,index)=>{
                                 su += 1;
                                html+='<tr >';
                                html+='<td> <input type="text" readonly id="factory_title'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][factory_title]" value="'+r.factory_title+'" style="width: 170px"/></td>';
                                html+='<td> <input type="text" readonly id="product_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][product_name]" value="'+r.product_name+'" style="width: 170px"/></td>';
                                html+='<td> <input type="text" readonly id="costmode_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][costmode_name]" value="'+r.costmode_name+'" style="width: 170px"/></td>';

                                if(r.type == 1){
                                    html+='<td> <input type="text" readonly onblur = "cost_money()" id="cost_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][cost_money]" value="'+r.cost_money+'" style="width: 70px"/></td>';
                                    html+='<td> <input type="text" readonly onblur = "cost_money()" id="real_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][real_money]" value="'+r.real_money+'" style="width: 70px"/></td>';
                                    html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'" checked name="checkbox'+su+'" data-line="<%='+su+'%>"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';

                                }else{
                                    html+='<td> <input type="text" onblur = "cost_money()" id="cost_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][cost_money]" value="'+r.cost_money+'" style="width: 70px"/></td>';
                                    html+='<td> <input type="text" onblur = "cost_money()" id="real_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][real_money]" value="'+r.real_money+'" style="width: 70px"/></td>';
                                    html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'" name="checkbox'+su+'" data-line="<%='+su+'%>"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';

                                }

                                html+='</tr>';
                            });
                            $('.lyj_tbody').append(html);
                            var len = $('#linetable tr').length;
                            console.log("lllllll"+len);
                            var cost_money_sun = 0;
                            var real_money_sun = 0;
                            for (var i = 1; i < len - 1; i++) {
                                var cost_money = $("#cost_money"+i).val();
                                var real_money = $("#real_money"+i).val();
                                console.log("cost_money"+cost_money);
                                cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                real_money_sun = Number(real_money_sun) + Number(real_money);
                                /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                                //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                                //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                            }

                            $('#all_quantity').val(cost_money_sun);
                            if(work_bao == '在保' && popVal == 2){
                                real_money_sun = 0;
                            }
                            $('#all_quantity_real').val(real_money_sun);
                        }
                        /* //直接给页面的该行数据定义值
                         $("#factory_title"+line).val(data.row.factory_title);
                         $("#product_name"+line).val(data.row.product_name);
                         $("#costmode_name"+line).val(data.row.cost_name);
                         $("#cost_money"+line).val(data.row.cost_money);*/

                        var len = $('#linetable tr').length;
                        console.log(len);
                        var cost_money_sun = 0;
                        var real_money_sun = 0;
                        len = len+40;
                        for (var i = 1; i < len - 1; i++) {
                            var checkbox = $("#checkbox"+i).val();
                            console.log("checkbox"+checkbox);
                            var cost_money = $("#cost_money"+i).val();
                            var real_money = $("#real_money"+i).val();
                            //cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                           // real_money_sun = Number(real_money_sun) + Number(real_money);
                            if(!isNaN(parseFloat(cost_money))){
                                cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                // cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                console.log(i+'aa');
                            }else{
                                cost_money_sun = Number(cost_money_sun);
                                console.log(i+'a');
                            }
                            if(!isNaN(parseFloat(real_money))){
                                console.log(i+'bb');
                                real_money_sun = Number(real_money_sun) + Number(real_money);
                            }else{
                                real_money_sun = Number(real_money_sun);
                                console.log(i+'b');
                            }
                            /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                            //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                            //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                        }

                        $('#all_quantity').val(cost_money_sun);
                        if(work_bao == '在保' && popVal == 2){
                            real_money_sun = 0;
                        }

                        $('#all_quantity_real').val(real_money_sun);

                    }
                });
                return false;
            });
            $(document).on("click", ".btn-removeline", function () {
                /*if ($('#linetable tr').length == 3) {
                    // alert(__("Can't delete"));
                    // return false;
                    Toastr.info("这是最后一条了！");
                    throw new Error('Generated error manually to stop execution of script');
                }*/
                // 先找到最近的具有“fieldlist”类的元素，这里则是html中的table，将其赋值给变量container；
                var container = $(this).closest(".fieldlist");
                //定义一个tagName，先去寻找container中是否有data-tag（同data-name，data-template）,如果没有就判断container是否是一个table,如果是tagName的值为tr,否则为dd
                var tagName = container.data("tag") || (container.is("table") ? "tr" : "dd");
                //找到最近的具有tagName标签（这里即tr）
                /*Toastr.info("删除成功！"+container.data("tag"));
                Toastr.info("删除成功！"+container.is("table"));
                Toastr.info("删除成功！"+tagName);*/
                $(this).closest(tagName).remove();
                //refresh(container);
                Toastr.info("删除成功！");
                //设置行号的值


                var len = $('#linetable tr').length;
                var cost_money_sun = 0;
                var real_money_sun = 0;
                len = len+40;
                for (var i = 1; i < len - 1; i++) {
                    var cost_money = $("#cost_money"+i).val();
                    var real_money = $("#real_money"+i).val();
                    //cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                   // real_money_sun = Number(real_money_sun) + Number(real_money);
                    if(!isNaN(parseFloat(cost_money))){
                        cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                        // cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                        console.log(i+'aa');
                    }else{
                        cost_money_sun = Number(cost_money_sun);
                        console.log(i+'a');
                    }
                    if(!isNaN(parseFloat(real_money))){
                        console.log(i+'bb');
                        real_money_sun = Number(real_money_sun) + Number(real_money);
                    }else{
                        real_money_sun = Number(real_money_sun);
                        console.log(i+'b');
                    }
                   /* $('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                    //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                    //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                }
                $('#all_quantity').val(cost_money_sun);
                $('#all_quantity_real').val(real_money_sun);
                //执行删除的时候总数进行变更
                var all_quantity = 0;//设置变量all_quantity为0
                var shuliang = 0;
                for(var j = 1;j<50;j++){
                    //获取单行的数量
                    shuliang  = $('#quantity' + j).val();
                    if(shuliang == ""){
                        shuliang = 0;
                    }
                    else if(Number(shuliang) >0){
                        //大于零的话，总数量就等于初始的总数量加上当前行的数量
                        all_quantity = Number(all_quantity) + Number(shuliang);
                    }
                }
               // console.log(all_quantity);
                //总数量的值就是经过循环计算出来的值

            });
            Controller.api.bindevent();
        },
        xiugai: function () {
            $(document).on('change','#c-product_id',function () {
                var val = $("#c-product_id").val();
                $.ajax({
                    async: true,
                    url: 'work/getproduct',
                    type: 'GET',
                    data : { id : val },
                    dataType: 'json',
                    timeout: 30000,
                    success: function (rec) {
                        // $("#c-flow_id").val(rec.rows.mobile)
                        $("#c-product_name").val(rec.rows.product_name);
                        $("#c-factory_title").val(rec.rows.factory_title);
                        $("#c-factory_name").val(rec.rows.factory_name);
                        $("#c-factory_phone").val(rec.rows.factory_phone);
                        $("#c-factory_address").val(rec.rows.factory_address);
                    },
                });
            });
            Controller.api.bindevent();
        },
        xiugaiputong: function () {

            Controller.api.bindevent();
        },
        complete: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-complete-click', function () {

                let complete_remarks = $('#c-complete_remarks').val();
                let gcremarks = $('#c-gcremarks').val();
                let id = $('#c-id').val();
                //let id = $('#id').val();
                $.post('work/complete', {
                    id,
                    complete_remarks,
                    gcremarks
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        tongxiugai: function () {
            Controller.api.bindevent();
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                    type:r.type,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                let su = 0;
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{

                        su += 1;
                        html+='<tr >';
                        html+='<td> <input type="text" id="factory_title'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][factory_title]" value="'+r.factory_title+'" style="width: 170px"/></td>';
                        html+='<td> <input type="text" id="product_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][product_name]" value="'+r.product_name+'" style="width: 170px"/></td>';
                        html+='<td> <input type="text" id="costmode_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][costmode_name]" value="'+r.costmode_name+'" style="width: 170px"/></td>';
                        html+='<td> <input type="text" onblur = "cost_money()" id="cost_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][cost_money]" value="'+r.cost_money+'" style="width: 70px"/></td>';
                        html+='<td> <input type="text" onblur = "cost_money()" id="real_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][real_money]" value="'+r.real_money+'" style="width: 70px"/></td>';


                    if(r.type == 1){
                        html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'" checked name="checkbox'+su+'"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';
                    }else{
                        html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'"  name="checkbox'+su+'"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';
                    }
                        html+='</tr>';

                });
                $('.lyj_tbody').html(html);
            }
            $(document).on("click", ".fachoosetable", function () {
                var that = this;
                //获取该界面的前端页面传来的line（前端展示的是data-line）
                var line = $(this).data("line") ? $(this).data("line") : false;
                //获取该界面的前端界面传来的url
                var product_id = $("#c-product_id").val();
                var factory_id = $("#c-factory_id").val();
                var url = $(this).data("url") ? $(this).data("url") : (typeof Backend !==
                'undefined' ? "cost/select?product_id=": "");
                //打开弹窗
                // console.log(product_id)
                //parent.Fast.api.open(url + "?line=" + line + "&product_id="+product_id, __('Choose'), {
                tables_list=[];
                parent.Fast.api.open(url + product_id+"&factory_id="+factory_id, __('Choose'), {
                    //回传值
                    callback: function (data) {
                        console.log("返回数据"+data);
                        console.log(line);
                        $.ajax({
                            url: 'cost/selectQr?ids='+data,
                            type: 'GET',
                            dataType: 'json',
                            data: {},
                            success: function (res) {
                                res.forEach(r=>{
                                    tables_list.push(
                                        {
                                            factory_title:r.factory_title,
                                            product_name:r.product_name,
                                            costmode_name:r.cost_name,
                                            cost_money:r.cost_money,
                                            real_money:r.real_money,
                                            qi:r.qi,
                                            id:r.id,
                                        }
                                    );
                                });
                                getListtbody();
                            }
                        });
                        let su = $('.lyj_tbody tr').length;
                         su = su+20;
                        function getListtbody(){
                            var html='';
                            console.log(6666,tables_list);
                            tables_list.forEach((r,index)=>{
                                su += 1;
                                html+='<tr >';
                                html+='<td> <input type="text" id="factory_title'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][factory_title]" value="'+r.factory_title+'" style="width: 170px"/></td>';
                                html+='<td> <input type="text" id="product_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][product_name]" value="'+r.product_name+'" style="width: 170px"/></td>';
                                html+='<td> <input type="text" id="costmode_name<%='+su+'%>" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][costmode_name]" value="'+r.costmode_name+'" style="width: 170px"/></td>';
                                html+='<td> <input type="text" onblur = "cost_money()" id="cost_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][cost_money]" value="'+r.cost_money+'" style="width: 70px"/></td>';
                                html+='<td> <input type="text" onblur = "cost_money()" id="real_money'+su+'" className="form-control" data-line="<%='+su+'%>" name="row[linedetail]['+su+'][real_money]" value="'+r.real_money+'" style="width: 70px"/></td>';
                                if(r.type == 1){
                                    html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'" checked name="checkbox'+su+'"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';
                                }else{
                                    html+='<td><input onclick="cost_money()" type="checkbox" id="checkbox'+su+'" name="checkbox'+su+'"><span class="btn btn-sm btn-danger btn-removeline"><i class="fa fa-times"></i></span> </td>';

                                }

                                html+='</tr>';
                            });
                            $('.lyj_tbody').append(html);
                            var len = $('#linetable tr').length;
                            console.log("lllllll"+len);
                            var cost_money_sun = 0;
                            var real_money_sun = 0;
                            len = len+40;
                            for (var i = 1; i < len - 1; i++) {
                                var cost_money = $("#cost_money"+i).val();
                                var real_money = $("#real_money"+i).val();
                                console.log("cost_money"+cost_money);
                                //cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                               // real_money_sun = Number(real_money_sun) + Number(real_money);
                                if(!isNaN(parseFloat(cost_money))){
                                    cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                    // cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                                    console.log(i+'aa');
                                }else{
                                    cost_money_sun = Number(cost_money_sun);
                                    console.log(i+'a');
                                }
                                if(!isNaN(parseFloat(real_money))){
                                    console.log(i+'bb');
                                    real_money_sun = Number(real_money_sun) + Number(real_money);
                                }else{
                                    real_money_sun = Number(real_money_sun);
                                    console.log(i+'b');
                                }
                                /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                                //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                                //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                            }

                            $('#all_quantity').val(cost_money_sun);
                            $('#c-cost').val(cost_money_sun);
                            $('#all_quantity_real').val(real_money_sun);
                            $('#c-real_cost').val(real_money_sun);
                        }
                        /* //直接给页面的该行数据定义值
                         $("#factory_title"+line).val(data.row.factory_title);
                         $("#product_name"+line).val(data.row.product_name);
                         $("#costmode_name"+line).val(data.row.cost_name);
                         $("#cost_money"+line).val(data.row.cost_money);*/

                        var len = $('#linetable tr').length;
                        console.log(len);
                        var cost_money_sun = 0;
                        for (var i = 1; i < len - 1; i++) {
                            var checkbox = $("#checkbox"+i).val();
                            console.log("checkbox"+checkbox);
                            var cost_money = $("#cost_money"+i).val();
                            cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                            /*$('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                            //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                            //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                        }

                        $('#c-cost').val(cost_money_sun);
                    }
                });
                return false;
            });
            $(document).on("click", ".btn-removeline", function () {
                /*if ($('#linetable tr').length == 3) {
                    // alert(__("Can't delete"));
                    // return false;
                    Toastr.info("这是最后一条了！");
                    throw new Error('Generated error manually to stop execution of script');
                }*/
                // 先找到最近的具有“fieldlist”类的元素，这里则是html中的table，将其赋值给变量container；
                var container = $(this).closest(".fieldlist");
                //定义一个tagName，先去寻找container中是否有data-tag（同data-name，data-template）,如果没有就判断container是否是一个table,如果是tagName的值为tr,否则为dd
                var tagName = container.data("tag") || (container.is("table") ? "tr" : "tr");
                //找到最近的具有tagName标签（这里即tr）
              /*  Toastr.info("删除成功！"+container.data("tag"));
                Toastr.info("删除成功！"+container.is("table"));
                Toastr.info("删除成功！"+tagName);*/
                $(this).closest(tagName).remove();
                //refresh(container);




                var len = $('#linetable tr').length;
                var cost_money_sun = 0;
                var real_money_sun = 0;
                len = len+40;
                for (var i = 1; i < len - 1; i++) {
                   // var checkbox = document.getElementById('checkbox'+i);
                   // var isChecked = checkbox.checked;

                    var cost_money = $("#cost_money"+i).val();
                    var real_money = $("#real_money"+i).val();
                    /*if(isChecked == true){
                        cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                       // cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                        real_money_sun = Number(real_money_sun) + Number(real_money);
                    }*/
                    if(!isNaN(parseFloat(cost_money))){
                        cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                        // cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                        console.log(i+'aa');
                    }else{
                        cost_money_sun = Number(cost_money_sun);
                            console.log(i+'a');
                    }
                    if(!isNaN(parseFloat(real_money))){
                        console.log(i+'bb');
                        real_money_sun = Number(real_money_sun) + Number(real_money);
                    }else{
                        real_money_sun = Number(real_money_sun);
                        console.log(i+'b');
                    }
                    console.log(cost_money_sun);
                    console.log(cost_money_sun);
                   //// cost_money_sun = Number(cost_money_sun) + Number(cost_money);
                    /* $('#linetable tr:eq(' + i + ') td:first').find('input').val(i);*/
                    //查找id为table的表格内索引为i的行中的第一个单元格，然后将索引i设置为文本内容。
                    //tr:eq(' + i + ') 是一个用于选择HTML元素的jQuery选择器，意思是选取序号为i的表格行（table row）。
                }
                console.log(33333333);
                console.log(cost_money_sun);
                $('#all_quantity').val(cost_money_sun);
                $('#c-cost').val(cost_money_sun);
                $('#all_quantity_real').val(real_money_sun);
                $('#c-real_cost').val(real_money_sun);
                Toastr.info("删除成功！");
                //设置行号的值

                //执行删除的时候总数进行变更
                var all_quantity = 0;//设置变量all_quantity为0
                var shuliang = 0;
                for(var j = 1;j<50;j++){
                    //获取单行的数量
                    shuliang  = $('#quantity' + j).val();
                    if(shuliang == ""){
                        shuliang = 0;
                    }
                    else if(Number(shuliang) >0){
                        //大于零的话，总数量就等于初始的总数量加上当前行的数量
                        all_quantity = Number(all_quantity) + Number(shuliang);
                    }
                }
                // console.log(all_quantity);
                //总数量的值就是经过循环计算出来的值

            });
        },
        import: function () {
            Controller.api.bindevent();
        },
        usersend: function () {
            Controller.api.bindevent();
        },
        usersendlook: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-usersendlook-click', function () {
                parent.layer.closeAll();
            });
        },
        sclookdetection: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-sclook-click', function () {
                let id = $("#c-id").val();
                parent.Fast.api.open('work/detection?ids='+id, __('上传检测报告'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            $(document).on('click', '.btn-sclookre-click', function () {
                parent.layer.closeAll();
            });



        },
        lookdetection: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-look-click', function () {
                let id = $("#c-id").val();
                parent.Fast.api.open('work/confirmdetection?ids='+id, __('待确认检测结果'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            $(document).on('click', '.btn-lookre-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        bohuide: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-bohuide-click', function () {
                parent.layer.closeAll();
            });
        },
        worklog: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-log-click', function () {
                parent.layer.closeAll();
            });
        },
        shenhelook: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-shenhelook-click', function () {
                parent.layer.closeAll();
            });
        },
        shenhechehui: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-shenhechehuigb-click', function () {
                parent.layer.closeAll();
            });
            $(document).on('click', '.btn-shenhechehui-click', function () {

                let chehui = 11;
                let id = $('#c-id').val();
                //let id = $('#id').val();
                $.post('work/shenhechehui', {
                    id,
                    chehui
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
        },
        factorysend: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-factorysend-click', function () {
                let admin_shipper_id = $("#c-admin_shipper_id").val();
                let admin_shipper_code = $("#c-admin_shipper_code").val();
                let factorysend_time = $("#c-factorysend_time").val();
                let id = $('#c-id').val();
                let remarks = $('#c-remarks').val();
                let voucher = $('#c-voucher').val();
                let is_liugc = $('#c-is_liugc').val();
                let gcremarks = $('#c-gcremarks').val();
                let confirmdetection_time = $('#c-confirmdetection_time').val();
                if(admin_shipper_id != 10000 && admin_shipper_code == ''&& is_liugc == 0){
                    alert("物流单号必传");
                    return;
                }
                //let id = $('#id').val();
                $.post('work/factorysend', {
                    id,
                    remarks,
                    voucher,
                    admin_shipper_id,
                    admin_shipper_code,
                    is_liugc,
                    factorysend_time,
                    gcremarks,
                    confirmdetection_time
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-factorysendre-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        factorysendlook: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-factorysendrelook-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        shvoucherbh: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-shvoucherbhsure-click', function () {
                let voucher_re = $("#c-voucher_re").val();
                let id = $('#c-id').val();
                //let id = $('#id').val();
                $.post('work/shvoucherbhsu', {
                    id,
                    voucher_re
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });

            $(document).on('click', '.btn-shvoucherre-click', function () {
                parent.layer.closeAll();
            });
        },
        shvoucher: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-shvoucher-click', function () {
                /*let voucher = $("#c-voucher").val();
                let id = $('#c-id').val();*/
                let order = $(this).data('order');
                let confirmdetection_time = $('#c-confirmdetection_time').val();
                let id = $('#c-id').val();
                let status = 9;
                $.post('work/shvoucher', {
                    id,
                    confirmdetection_time,
                    status
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            //驳回
            $(document).on('click', '.btn-shvoucherrebh-click', function () {
                //let id = $(this).data('id');
                /* var index = parent.layer.getFrameIndex(window.name);
                 parent.layer.close(index);
                 parent.layer.closeAll("refresh");*/
                let id = $("#c-id").val();
                // alert(id);
                parent.Fast.api.open('work/shvoucherbh?ids='+id, __('驳回凭证'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            $(document).on('click', '.btn-shvoucherre-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        shvoucherlook: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-shvoucherrelook-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        voucherlook: function () {
            Controller.api.bindevent();
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        voucher: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-voucher-click', function () {
                let is_voucher = 1;
                let voucher = $("#c-voucher").val();
                let cost = $("#c-cost").val();
                let id = $('#c-id').val();
                let confirmdetection_time = $('#c-confirmdetection_time').val();
                var isstatus = document.querySelector('input[name="isstatus"]:checked').value;
               // let isstatus = $('#isstatus-2').val();
                //alert(isstatus);
                $.post('work/voucher', {
                     id,
                    voucher,
                    isstatus,
                    is_voucher,
                    cost,
                    confirmdetection_time
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-voucherre-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        confirmdetection: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-confirmdetection-click', function () {
                let order = $(this).data('order');
                let id = $("#c-id").val();
                let cost = $("#c-cost").val();
                let real_cost = $("#c-real_cost").val();
                let cost_content = $("#c-cost_content").val();
                let sales_status = $("#c-sales_status").val();
                let is_huangou = $("#c-is_huangou").val();
               // alert(real_cost);
                //alert(is_huangou);
                let confirmdetection_time = $("#c-confirmdetection_time").val();
                //let id = $('#id').val();
                $.post('work/confirmdetection', {
                     id,
                    cost,
                    real_cost,
                    cost_content,
                    sales_status,
                    is_huangou,
                    confirmdetection_time
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        //parent.location.reload();
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-confirmdetectionbao-click', function () {
                let order = $(this).data('order');
                let id = $("#c-id").val();
                let cost = $("#c-cost").val();
                let real_cost = $("#c-real_cost").val();
                let cost_content = $("#c-cost_content").val();
                let sales_status = $("#c-sales_status").val();
                let is_huangou = $("#c-is_huangou").val();
                let confirmdetection_time = $("#c-confirmdetection_time").val();
                //let id = $('#id').val();
                $.post('work/confirmdetectionbao', {
                    id,
                    cost,
                    real_cost,
                    cost_content,
                    sales_status,
                    is_huangou,
                    confirmdetection_time
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        //parent.location.reload();
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-confirmdetectionre-click', function () {
                parent.layer.closeAll();
            });
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/workCost?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    factory_title:r.factory_title,
                                    product_name:r.product_name,
                                    costmode_name:r.costmode_name,
                                    cost_money:r.cost_money,
                                    real_money:r.real_money,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
        /**
        * 物料表格
            */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.costmode_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.cost_money+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.real_money+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
        },
        confirm: function () {
            $(document).on('change','#c-product_id',function () {
                var val = $("#c-product_id").val();
                $.ajax({
                    async: true,
                    url: 'work/getproduct',
                    type: 'GET',
                    data : { id : val },
                    dataType: 'json',
                    timeout: 30000,
                    success: function (rec) {
                        // $("#c-flow_id").val(rec.rows.mobile)
                        $("#c-product_name").val(rec.rows.product_name);
                        $("#c-factory_title").val(rec.rows.factory_title);
                        $("#c-factory_name").val(rec.rows.factory_name);
                        $("#c-factory_phone").val(rec.rows.factory_phone);
                        $("#c-factory_address").val(rec.rows.factory_address);
                        if(rec.rows.product_name == "数据线"){
                            $("#sone").hide();//表示display:block,
                            $("#stwo").show();//表示display:none;
                        }else{
                            $("#sone").show();//表示display:block,
                            $("#stwo").hide();//表示display:none;
                        }
                    },
                });
            });
            //$("#zhuanji").hide();
            Controller.api.bindevent();
            $(document).on('click', '.btn-confirm-click', function () {
                let order = $(this).data('order');
                let status = 5;
                let id = $('#c-id').val();
                let product_id = $('#c-product_id').val();
                let zhuanji_code = $('#c-zhuanji_code').val();
                let confirm_time = $('#c-confirm_time').val();

                //alert(zhuanji);
                //let id = $('#id').val();
                $.post('work/confirm', {
                     id,
                    status,
                    confirm_time,
                    zhuanji_code,
                    product_id
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-confirmjicuo-click', function () {
                //let id = $(this).data('id');
                /* var index = parent.layer.getFrameIndex(window.name);
                 parent.layer.close(index);
                 parent.layer.closeAll("refresh");*/
                let id = $("#c-id").val();
                // alert(id);
                parent.Fast.api.open('work/confirmjicuo?ids='+id, __('驳回工单'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
           /* $(document).on('click', '.btn-confirmjicuo-click', function () {
                let order = $(this).data('order');
                let status = 5;
                let id = $('#c-id').val();
                let product_id = $('#c-product_id').val();
                let zhuanji_code = $('#c-zhuanji_code').val();
                let confirm_time = $('#c-confirm_time').val();

                //alert(zhuanji);
                //let id = $('#id').val();
                $.post('work/confirmjicuo', {
                    id,
                    status,
                    confirm_time,
                    zhuanji_code,
                    product_id
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });*/
            $(document).on('click', '.btn-confirmre-click', function () {
                parent.layer.closeAll();
            });
        },
        service: function (){
            tables_list=[];
            //获取初始化的物料清单
            let id = $("#c-id").val();
            getConfig();
            function getConfig(){
                $.ajax({
                    url: 'work/serviceList?id='+id,
                    type: 'POST',
                    dataType: 'json',
                    data: {},
                    success: function (res) {
                        res.forEach(r=>{
                            tables_list.push(
                                {
                                    id:r.id,
                                    product_name:r.product_name,
                                    product_code:r.product_code,
                                    res_receiver:r.res_receiver,
                                    channel_name:r.channel_name,
                                    status_name:r.status_name,
                                    createtime:r.createtime,
                                    factory_title:r.factory_title,
                                }
                            );
                        });
                        getListtbody();
                    }
                });
            }
            /**
             * 物料表格
             */
            function getListtbody(){
                var html='';
                console.log(6666,tables_list);
                tables_list.forEach((r,index)=>{
                    html+='<tr >';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.id+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.product_code+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.res_receiver+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.channel_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.status_name+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.createtime+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; ">'+r.factory_title+'</td>';
                    html+='<td style="text-align: center; vertical-align: middle; " class="btn-service-click" data-order=\'{"id":'+r.id+'}\'>'+'查看'+'</td>';
                    html+='</tr>';
                });
                $('.lyj_tbody').html(html);
            }
            $(document).on('click', '.btn-service-click', function () {
                let order = $(this).data('order');
                let id = order.id;
                parent.Fast.api.open('work/complete?ids='+id, __('查看'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            $(document).on('click', '.btn-bohuide-click', function () {
                parent.layer.closeAll();
            });
            $(document).on('click', '.btn-service-clo-click', function () {
                parent.layer.closeAll();
            });
            /*$(document).on('click', '.btn-service-click', function () {
                let order = $(this).data('order');
                let ids = order.id;
                $.get('work/complete', {
                    ids
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.location.reload();
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });*/
        },

        confirmlook: function () {
            Controller.api.bindevent();
            $(document).on('click', '.btn-confirmrelook-click', function () {
                parent.layer.closeAll();
            });
        },
        shenhe: function () {

            Controller.api.bindevent();
           // Controller.api.shenhesave();
            //取消，支付
            $(document).on('click', '.btn-status-click', function () {
                let order = $(this).data('order');
                let image = $("#c-image").val();
                let order_image = $("#c-order_image").val();
                //let id = $('#id').val();
                let work_bao = $("input[type=radio][name='row[work_bao]']:checked").val();
                $.post('work/shenhere', {
                    work_bao,
                    image,
                    order_image,
                    ...order
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            //驳回
            $(document).on('click', '.btn-statusre-click', function () {
                //let id = $(this).data('id');
               /* var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.layer.closeAll("refresh");*/
                let id = $("#c-id").val();
               // alert(id);
                parent.Fast.api.open('work/shenhere?ids='+id, __('驳回工单'),{
                    //接收传过来的参数
                    callback:function(value){
                        //在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
                    }
                });
            });
            $(document).on('click', '.btn-statusrere-click', function () {
                parent.layer.closeAll();
            });

        },
        confirmjicuo: function () {

            Controller.api.bindevent();
            // Controller.api.shenhesave();
            //取消，支付
            $(document).on('click', '.btn-status-su-click', function () {
                let order = $(this).data('order');
                let status = 5;
                let id = $('#c-id').val();
                let product_id = $('#c-product_id').val();
                let user_shipper_id = $('#c-user_shipper_id').val();
                let user_shipper_code = $('#c-user_shipper_code').val();
                let confirm_time = $('#c-confirm_time').val();

                //alert(zhuanji);
                //let id = $('#id').val();
                $.post('work/confirmjicuo', {
                    id,
                    status,
                    confirm_time,
                    user_shipper_code,
                    user_shipper_id,
                    product_id
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-statusrere-click', function () {
                parent.layer.closeAll();
            });

        },
        shenhere: function () {

            Controller.api.bindevent();
            // Controller.api.shenhesave();
            //取消，支付
            $(document).on('click', '.btn-status-su-click', function () {
                //let order = $(this).data('order');
                let reject = $("#c-reject").val();
                let id = $('#c-id').val();
                $.post('work/shenheresu', {
                     id,
                    reject
                }, function (res) {
                    if (res.code == 1) {
                        parent.Toastr.success(res.msg);
                        parent.$(".btn-refresh").trigger("click");
                        parent.layer.closeAll();

                    } else {
                        parent.Toastr.error(res.msg);
                    }
                });
            });
            $(document).on('click', '.btn-statusrere-click', function () {
                parent.layer.closeAll();
            });

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },shenhesave: function () {
            // parent.location.reload();
            window.close();
        },
    };
    return Controller;
});
